package com.deyang.ui.fragment;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;


import com.deyang.callback.ValueCallBack;
import com.deyang.config.ConfigRes;
import com.deyang.entity.BaseResponse;
import com.deyang.entity.TokenInfo;
import com.deyang.entity.UserInfo;
import com.deyang.maillist.R;
import com.deyang.service.IHttpService;
import com.deyang.tool.HttpTool;
import com.deyang.ui.activity.LoginActivity;
import com.deyang.util.ImageUtil;
import com.deyang.util.RetrofitUtil;
import com.deyang.util.SpUtil;

import butterknife.BindView;
import butterknife.OnClick;
import jp.wasabeef.glide.transformations.CropCircleTransformation;

public class MyFragment extends BaseFragment {


    @BindView(R.id.iv_userHeadIcon)
    ImageView ivUserHeadIcon;
    @BindView(R.id.tv_realName)
    TextView tvRealName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;

    @BindView(R.id.ll_updateMailList)
    LinearLayout llUpdateMailList;


    private IHttpService httpService;


    private AlertDialog loginoutDialog;

    @Override
    protected int initLayoutRes() {
        return R.layout.fragment_my;
    }

    @Override
    protected void processLogic() {
        initView();
        getUserInfo();
    }

    private void initView() {
        AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
        builder.setTitle("退出登录")
                .setMessage("确定退出登录？")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        SpUtil.putObject(mApp, ConfigRes.STORAGE_USER_INFO, new TokenInfo());
                        mApp.setTokenInfo(null);
                        mApp.setUserInfo(null);
                        mApp.finishAllActivity();
                        startActivity(new Intent(mApp, LoginActivity.class));
                    }
                })
                .setNegativeButton("取消", null);
        loginoutDialog = builder.create();

        httpService = RetrofitUtil.buildRetrofit(mActivity).create(IHttpService.class);

        ImageUtil.loadImage(mActivity, ivUserHeadIcon, R.mipmap.default_mail_man, R.drawable.load_fail, new CropCircleTransformation());

    }


    @OnClick({
            R.id.btn_loginout,
            R.id.ll_updateMailList,
    })
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_loginout:
                loginoutDialog.show();
                break;
            case R.id.ll_updateMailList:

                break;
        }
    }

    /**
     * 获取个人信息
     */
    private void getUserInfo() {
    }

}
